#include "stdafx.h"
#include "auto_static.h"

BOOL
auto_static::auto_change_size()
{
	RECT   rect; 
	SIZE   size; 
	char   buf[512]; 
	CDC *pdc = GetDC();
	HDC   hDC   =   GetDC()->GetSafeHdc(); 
	GetWindowText(buf,   sizeof(buf)); 
	GetTextExtentPoint(hDC,   buf,   strlen(buf),   &size); 
	GetWindowRect(&rect); 
	SetWindowPos(0,   0,   0,  this->max_length_ > size.cx ? size.cx : this->max_length_ ,   rect.bottom 
		-rect.top,   SWP_NOMOVE|SWP_NOZORDER); 
	ReleaseDC(pdc);
	return TRUE;
}

BOOL
auto_static::set_window_text(LPCTSTR lptext)
{
	SetWindowText(lptext);
	auto_change_size();
	return TRUE;
}